//
//  HYMovieMainView.m
//  KaiJing
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYMovieMainView.h"
#import "UIButton+WebCache.h"
#import "SZYingKUMainViewController.h"
#import "CJCellBottomView.h"
#define movieImageHeight ([UIScreen mainScreen].bounds.size.height -  113)

@interface HYMovieMainView ()

@end

@implementation HYMovieMainView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addView];
    }
    return self;

}

- (void) addView {
    
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, movieImageHeight)];
   // _scrollView.backgroundColor = [UIColor yellowColor];
    
   
    _scrollView.contentOffset = CGPointMake(0, kScreenHeight);
    _scrollView.bounces = YES;
    _scrollView.pagingEnabled = YES;
    _scrollView.alwaysBounceHorizontal = NO;
    _scrollView.alwaysBounceVertical = YES;
    [self addSubview:_scrollView];

    
    /**注意 这段先用临时的数,等解析好了传过来数组,然后用数组的contont */
    
}

- (void)setArray:(NSMutableArray *)array
{
    _array = array;
    for (int i = 1; i <= array.count; i ++) {
        _model = array[i - 1];
        
       //大的scrollView
        _scrollView.contentSize = CGSizeMake(kScreenWidth, movieImageHeight *(i));
        
        //大的图片 因为点击 写成button
        _movieBigImageView = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _movieBigImageView.frame = CGRectMake((kScreenWidth / 5),movieImageHeight / 10 + movieImageHeight *(i - 1), (kScreenWidth / 5) *3, (movieImageHeight / 2));
            NSString *image = [NSString stringWithFormat:@"http://morguo.com/%@",_model.moviedata[@"image"]];
        [_movieBigImageView sd_setBackgroundImageWithURL:[NSURL URLWithString:image] forState:(UIControlStateNormal)];
        [_movieBigImageView addTarget:self action:@selector(image:) forControlEvents:(UIControlEventTouchUpInside)];
        [_scrollView addSubview:_movieBigImageView];
        _movieBigImageView.tag = 1000 + (i - 1);
        
        //大的图片下面的label
        _message = [[UILabel alloc] initWithFrame:CGRectMake(_movieBigImageView.left, _movieBigImageView.bottom + movieImageHeight / 20, _movieBigImageView.width, movieImageHeight / 5)];
        //_message.backgroundColor = [UIColor redColor];
        _message.text = _model.message;
        _message.numberOfLines = -1;
        _message.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:_message];
        
        
        //点赞等
        _bottomView = [[CJCellBottomView alloc] initWithFrame:CGRectMake(0, _message.bottom + 15, kScreenWidth, 25)];
        
        
        //点赞
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_norml"] forState:(UIControlStateNormal)];
        _bottomView.praiseLabel.text = @"赞";
//        [_bottomView.praiseButton addTarget:self action:@selector(praiseButton:) forControlEvents:(UIControlEventTouchUpInside)];
        //评论
        [_bottomView.commentButton setImage:[UIImage imageNamed:@"comment"] forState:(UIControlStateNormal)];
        _bottomView.commentLabel.text = @"评论";
        
        //更多
        [_bottomView.moreButton setImage:[UIImage imageNamed:@"more"] forState:(UIControlStateNormal)];
//        [_bottomView.moreButton addTarget:self action:@selector(moreButton:) forControlEvents:(UIControlEventTouchUpInside)];
        
        [_scrollView addSubview:_bottomView];

    }
    
}



- (void)image:(UIButton *)button {

    [_delegate changeBigImageButton:button];
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
